package com.pay.common;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;


public class HandlerInterceptorAdapter implements HandlerInterceptor {
    
    @Override
    public boolean preHandle(HttpServletRequest req, HttpServletResponse response, Object handler) throws Exception {
        String path = req.getServletPath();
        if(path != null && path.indexOf(".") == -1){
        	 System.out.println("-------"+req.getServletPath());
        	 
        	 if(path.endsWith("/user/login")){
        		 return true ;
        	 }
        	 
        	 if(path.endsWith("/user/logout")){
        		 return true;
        	 }
        	 
        	 if( req.getSession().getAttribute("username") == null ){ 
        		 response .sendRedirect(req.getContextPath()+"/sessionout.jsp");
        		 return false ;
        	 }
        	 return true ;
        	 
        }
       
        return true;
    }
    
    @Override
    public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3)
            throws Exception {
        
    }
    
    @Override
    public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3)
            throws Exception {
        
    }
}